<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.zhlx.duss.utils.SrmUtil" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%--OA流程节点信息SRM系统接口回传--%>
<%
    JSONObject jsonData = new JSONObject();
    BaseBean baseBean = new BaseBean();
    RecordSet rs = new RecordSet();
    String message = "";
    String status = "success";
    String requestid = Util.null2String(request.getParameter("requestid"));
    int formid = Util.getIntValue(request.getParameter("formid"));
    formid = Math.abs(formid);
    String src = Util.null2String(request.getParameter("src"));
    String remark = Util.null2String(request.getParameter("remark"));
    try {
        rs.executeQuery("select htly,spbh,bs from formtable_main_" + formid + " where requestid=?", requestid);
        rs.next();
        String htly = Util.null2String(rs.getString("htly"));
        String spbh = Util.null2String(rs.getString("spbh"));
        String bs = Util.null2String(rs.getString("bs"));
        if (!"0".equals(htly) && !"0".equals(bs)) {
            JSONObject paramJson = new JSONObject();
            String operatorStatus = "approve";
            String zt = "approving";
            int nextnodeid = 0;
            rs.executeQuery("select distinct userid,nodeid from workflow_currentoperator\n" +
                    " where (isremark in ('0','5','7') or (isremark='4' and (viewtype=0 or viewtype=-2)))  and requestid = ?", requestid);
            while (rs.next()) {
                nextnodeid = Util.getIntValue(rs.getString("nodeid"));
            }
            JSONObject reusltJson = SrmUtil.getNodebaseNodename(nextnodeid);
            String nodename = Util.null2String(reusltJson.getString("nodename"));
            String isend = Util.null2String(reusltJson.getString("isend"));
            if ("1".equals(isend) || "经办人归档".equals(nodename) || "电子经办人归档".equals(nodename)) {
                zt = "approve";
                rs.executeUpdate("update formtable_main_" + formid + " set bs=0 where requestid = ?", requestid);
                if ("退回归档勿修改".equals(nodename)) {
                    zt = "notApproved";
                    operatorStatus = "notApproved";
                }
            } else {
                if ("reject".equals(src)) {
                    operatorStatus = "notApproved";
                }
            }
            paramJson.put("oaId", requestid);
            paramJson.put("operatorStatus", operatorStatus);
            paramJson.put("operatorNode", nodename);
            paramJson.put("status", zt);
            paramJson.put("remark", SrmUtil.removeHTMLTags(remark));
            paramJson.put("spbh", spbh);
            baseBean.writeLog(">>>>>WeaCghjlcBackAction>>>>>paramJson=" + paramJson);
            Map<String, Object> dataMap = new HashMap<>();
            dataMap.put("jkdymc", "WeaCghjlcBackAction");
            dataMap.put("lcid", requestid);
            dataMap.put("dylc", requestid);
            dataMap.put("cz", src);
            JSONObject resultJson = SrmUtil.handleOKHttpRequest(paramJson, dataMap);
            baseBean.writeLog(">>>>>WeaCghjlcBackAction>>>>>resultJson=" + resultJson);
            String code = Util.null2String(resultJson.getString("code"));
            if ("success".equals(code)) {
                String success = resultJson.getString("success");
                String msg = resultJson.getString("msg");
                if (!"true".equals(success)) {
                    status = "failture";
                    message = msg;
                }
            } else {
                message = Util.null2String(resultJson.getString("message"));
                status = "failture";
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    jsonData.put("status", status);
    jsonData.put("message", message);
    out.print(jsonData.toJSONString());
%>




